package codeflyer.server;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import codeFlyer.web.api.Filter;
import codeFlyer.web.api.FilterChain;
import codeFlyer.web.api.HttpRequest;
import codeFlyer.web.api.HttpResponse;

/**
 * @author CodeFlyer
 * @date May 10, 2020
 * @version 1.0
 */

public class Chain implements FilterChain{
	
//	private Map<String, List<Filter>> filterMap = new HashMap<>();   //存储过滤器
	private List<Filter> filterList = null;
	private boolean executor = false;
//	private static boolean created = false;
	private int i = 0;
	private HttpRequest request;
	private HttpResponse response;
	
	public Chain(List<Filter> filterList,HttpRequest request,HttpResponse response) {
//		super();
		this.filterList = filterList;
		this.request = request;
		this.response = response;
	}

	public boolean isExecutor() {  //dispacher如果说dochain对象存在且executro为true意味着直线servlet
		return executor;
	}

//	public static boolean isCreated() {
//		return created;
//	}

	@Override
	public void doChain() {  //每调用一次执行一个
		// TODO Auto-generated method stub
		i++;
//		executor = true;
		if(i-1<filterList.size()) {
			filterList.get(i-1).doFitler(request, response,this);
			System.out.println("过滤器链i的值------>"+i);
//			executor = false;
		}else {
			executor = true;
		}
	}

}


